﻿Imports System.Data.SqlClient

Public Class Login
    Dim cmd As New SqlCommand
 
    Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        condb()
        txtusername.Focus()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try    
            cmd.Connection = cn
            cmd.CommandText = "select Username,Password from tblUser where Username=N'" & txtusername.Text & "' and Password=N'" & txtpassword.Text & "'"
            Dim reader As SqlDataReader
            reader = cmd.ExecuteReader
            If reader.HasRows Then
                Main.ShowDialog()
            Else

                MessageBox.Show("Username and Password incorrect", "", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

            reader.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub txtusername_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtusername.TextChanged
        condb()
        cmd.Connection = cn
        cmd.CommandText = "select usertype from tbluser where Username='" & txtusername.Text & "'"
        txtusertype.Text = cmd.ExecuteScalar
    End Sub
End Class